Logging
WOLF uses the spdlog library for logging. On top of it, we have implemented a custom logger macros that allow us to log messages with different levels of severity:
WOLF_TRACE(...): Displayed (in white) unless compiled with-D_WOLF_TRACE=FALSEWOLF_DEBUG(...): Only displayed (in cyan) if compiled in debug mode.WOLF_INFO(...): Displayed in green.WOLF_WARN(...): Displayed in yellow.WOLF_ERROR(...): Displayed in red.
All logging macros accept several inputs of type string and other types with defined stream (int, floats, Eigen objects, YAML::Nodes, etc.) At the begining of the message, the logger will print:
[severity][file_name Lline_number] function_name: message
The following code:
WOLF_TRACE("test trace ", 5, " ", 0.123);
WOLF_DEBUG("test debug ", 5, " ", 0.123);
WOLF_INFO("test info ", 5, " ", 0.123);
WOLF_WARN("test warn ", 5, " ", 0.123);
WOLF_ERROR("test error ", 5, " ", 0.123);
compiled in debug mode without disabling trace will output:
[trace][gtest_logging.cpp L45] TestBody: test trace 5 0.123 [debug][gtest_logging.cpp L52] TestBody: test debug 5 0.123 [info][gtest_logging.cpp L24] TestBody: test info 5 0.123 [warning][gtest_logging.cpp L31] TestBody: test warn 5 0.123 [error][gtest_logging.cpp L38] TestBody: test error 5 0.123
See also
The Macros for processors section explains the macro WOLF_PROC_DEBUG(...) specific for processors.
Conditional macros
For all levels, we also defined the conditional macros WOLF_xxxx_COND(condition, ...)
that only log the message if the condition is evaluated to true.
The following code:
WOLF_TRACE_COND(true, "This message should appear!");
WOLF_TRACE_COND(false, "This message should NOT appear!");
WOLF_DEBUG_COND(true, "This message should appear!");
WOLF_DEBUG_COND(false, "This message should NOT appear!");
WOLF_INFO_COND(true, "This message should appear!");
WOLF_INFO_COND(false, "This message should NOT appear!");
WOLF_WARN_COND(true, "This message should appear!");
WOLF_WARN_COND(false, "This message should NOT appear!");
WOLF_ERROR_COND(true, "This message should appear!");
WOLF_ERROR_COND(false, "This message should NOT appear!");
compiled in debug mode and without disabling trace will output:
[trace][gtest_logging.cpp L46] TestBody: This message should appear! [debug][gtest_logging.cpp L53] TestBody: This message should appear! [info][gtest_logging.cpp L25] TestBody: This message should appear! [warning][gtest_logging.cpp L32] TestBody: This message should appear! [error][gtest_logging.cpp L39] TestBody: This message should appear!
Macros for processors
There is an implementation of WOLF_DEBUG to be used in processors code.
Instead of enabling/disabling according to the build type, WOLF_PROC_DEBUG can be enabled and disabled by the user via YAML.
Each processor has the parameter debug_verbose_level to control which WOLF_PROC_DEBUG are displayed to the console:
If compiled in debug mode, all messages are displayed.
If compiled in release mode, logging depends on the value of
debug_verbose_level:none: No messages are displayed.derived: only theWOLF_PROC_DEBUG(...)placed in the derived processor are displayed.base: only theWOLF_PROC_DEBUG(...)placed in the base processor classes are displayed.all: All messages are displayed.
Analogously to the other macros, there is the WOLF_PROC_DEBUG_COND(condition, ...).
Note
This implementation requires Boost >= 1.73. If not found or earlier version, derived and base will behave like all.